// pages/ChatRoom/ChatRoom.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    InputText: '', //输入的文字
    Messages: [], //消息列表{:"isSelfSend":"是否我发送的","fromAccountImg":"头像","content":"内容","id":1}
    Timer:null,
    TestId:0,//测试id
    Last:'',//最后一个
  },

  InputText: function(ev) {
    this.setData({
      InputText: ev.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    wx.hideShareMenu({
      
    })
    // this.startTimer();
  },

  onUnload:function(){
    clearTimeout(this.data.Timer)
  },

  //定时器
  startTimer: function() {
    var that = this;
    this.setData({
      Timer: setTimeout(function () {
        console.log("请求消息:" + (new Date).getTime());
        // that.test();
        that.startTimer();
      }, 1000)
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    console.log("onPullDownRefresh");
  },

  scrollToUpper:function(ev){
    console.log("下拉");
  },

  scrollToLower: function (ev) {
    console.log("上啦");
  },

  /**
   * 发送消息
   */
  sendMsg: function(ev) {
    console.log("发送");

    var message = {}
    message.id=this.data.TestId;
    message.isSelfSend = 0;
    message.content = this.data.InputText;
    message.fromAccountImg = 'http://imgtu.5011.net/uploads/content/20170209/4934501486627131.jpg';
    this.data.Messages.push(message);

    this.setData({
      InputText: '',
      Messages: this.data.Messages,
      Last: "a" + this.data.TestId,
      TestId:this.data.TestId + 1,
    })
  },
})